package edu.nf.project.mappers.storeOperation.convention;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.nf.project.entitys.entity.storeOperation.convention.dish.Dish;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 菜品 Mapper 接口
 */
@Mapper
public interface DishMapper extends BaseMapper<Dish> {
    @Select("SELECT \n" +
            "    d.*,\n" +
            "    -- 查询每个菜品的已售数量\n" +
            "    (SELECT COALESCE(SUM(oi.quantity), 0) \n" +
            "     FROM customer_order_item oi \n" +
            "     WHERE oi.dish_id = d.dish_id) AS sold_quantity\n" +
            "FROM \n" +
            "    dish d")
    List<Dish> getDishList();
}